package sword.T39;

/**
 * @Author: 18362
 * @Create: 2022-04-08 22:32:47 星期五
 */

class Solution {
    public int majorityElement(int[] nums) {
        int maxNum = 0, cnt = 0;
        for (int i=0; i<nums.length; ++i) {
            if (cnt == 0) {
                cnt = 1;
                maxNum = nums[i];
            } else if (nums[i] == maxNum)
                cnt++;
            else
                cnt--;
        }
        return maxNum;
    }
}